package com.zoweunion.mechanic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zoweunion.mechanic.dao.TSSsUserMapper;
import com.zoweunion.mechanic.dao.TSTtOrderMapper;
import com.zoweunion.mechanic.entity.TSSsUserEntity;
import com.zoweunion.mechanic.entity.TSTtOrderEntity;
import com.zoweunion.mechanic.entity.vo.TSSsUserVO;
import com.zoweunion.mechanic.service.ITSSsUserService;
import com.zoweunion.mechanic.util.FunUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class TSSsUserServiceImpl extends ServiceImpl<TSSsUserMapper, TSSsUserEntity> implements ITSSsUserService {

    @Autowired
    private TSSsUserMapper tSSsUserMapper;

    @Autowired
    private TSTtOrderMapper tsTtOrderMapper;

    @Autowired
    private TSTtOrderServiceImpl tsTtOrderService;


    @Override
    public PageInfo listPage(Map<String, Object> map) {

        Integer pageSize = Integer.valueOf(map.get("pageSize").toString());
        Integer currentPage = Integer.valueOf(map.get("currentPage").toString());
        PageHelper.startPage(currentPage, pageSize);

        List<TSSsUserVO> mapList = tSSsUserMapper.findByCondition(map);
        PageInfo<TSSsUserVO> mapPageInfo = new PageInfo<>(mapList);
        return mapPageInfo;
    }


    @Override
    public List<TSSsUserVO> listCgByOrderId(String orderId) {

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",orderId);
        TSTtOrderEntity tsTtOrderVO =  tsTtOrderMapper.selectOne(queryWrapper);

        if(tsTtOrderVO.getWarehouselocationId()!=null){
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.eq("warehouse_id", tsTtOrderVO.getWarehouselocationId());
            List<TSSsUserEntity> listUser = tSSsUserMapper.selectList(wrapper);

            List<TSSsUserVO> tsSsUserVOList = FunUtil.entityToVoList(listUser,TSSsUserVO.class);

            return tsSsUserVOList;
        }

        return null;
    }


}

